// (function() {
// 	var parent = document.getElementById('parent');
// 	var child1 = document.getElementById('child1');
// 	var child2 = document.getElementById('child2');
// 	child2.innerHTML = child1.innerHTML;
// 	setInterval(function() {
// 		if (parent.scrollTop >= child1.scrollHeight) {
// 			parent.scrollTop = 0;
// 		} else {
// 			parent.scrollTop++;
// 		}
// 	}, 20);
// })

export function autoScrollTable(id) {
  var parent = document.querySelector('#' + id + ' div.el-table__body-wrapper.is-scrolling-none');
  var child = document.querySelector('#' + id + ' table.el-table__body');
  // console.log(parent);

  var interval = setInterval(function() {
    if (parent.scrollTop >= child.scrollHeight) {
      parent.scrollTop = 0;
    } else {
      let oldScrollTop = parent.scrollTop
      parent.scrollTop++;
      let newScrollTop = parent.scrollTop;

      if (oldScrollTop == newScrollTop) {
        parent.scrollTop = 0
      }
    }
  }, 200);

  return interval;
}

export function autoScrollList(id) {

   var parent = document.querySelector('#' + id );
   var child = document.querySelector('#' + id + ' .scroll-container');
   // console.log(parent);
   parent.scrollTop = 0;
   var interval = setInterval(function() {
     if (parent.scrollTop >= child.scrollHeight) {
       parent.scrollTop = 0;
     } else {
       let oldScrollTop = parent.scrollTop
       parent.scrollTop++;
       let newScrollTop = parent.scrollTop;

       if (oldScrollTop == newScrollTop) {
         parent.scrollTop = 0
       }
     }
   }, 200);

   return interval;
}

export function cancelScroll(interval) {
  clearInterval(interval);
}

export default {
  autoScrollTable,
  autoScrollList,
  cancelScroll
}
